package com.qianfeng.controller;

import com.qianfeng.dto.Page;
import com.qianfeng.dto.Result;
import com.qianfeng.entity.Attendance;
import com.qianfeng.entity.WorkType;
import com.qianfeng.service.AttendanceService;
import com.qianfeng.service.WorkTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@ResponseBody
@Controller
@CrossOrigin
@RequestMapping(value = "/attendance")
public class AttendanceController {

    @Autowired
    private WorkTypeService workTypeService;

    @Autowired
    private AttendanceService attendanceService;

    @RequestMapping(value = "/addAttendance")
    public Result addAttendance(@RequestBody Attendance attendance){
        attendanceService.addAttendance(attendance);
        Result result = new Result();
        return result;
    }

    /**
     * 删除角色
     * @param attendanceId
     * @return
     */
    @RequestMapping(value = "/deleteAttendance")
    public Result deleteAttendance(Integer attendanceId){
        attendanceService.deleteAttendance(attendanceId);
        Result result = new Result();
        return result;
    }

    /**
     * 更新角色
     * @param attendance
     * @return
     */
    @RequestMapping(value = "/updateAttendance")
    public Result updateAttendance(@RequestBody Attendance attendance){
        attendanceService.updateAttendance(attendance);
        Result result = new Result();
        return result;
    }

    @RequestMapping(value = "/getAttendancePage")
    public Result getAttendancePage(Integer pageNo,Integer pageSize){
        if(pageNo==null){
            pageNo=1;
        }
        if(pageSize==null){
            pageSize=5;
        }
        Page page = attendanceService.getAttendancePage(pageNo,pageSize);
        Result result = new Result();
        result.setData(page);
        return result;

    }


    @RequestMapping(value = "/getListByAttendanceId")
    public Result getListByAttendanceId(Integer attendanceId){
        List<Attendance> listByAttendanceId = attendanceService.getListByAttendanceId(attendanceId);
        Result result = new Result();
        result.setData(listByAttendanceId);
        return result;

    }

    @RequestMapping(value = "/getWorkTypeList")
    public Result getWorkTypeList(){
        List<WorkType> workTypeList = workTypeService.getWorkTypeList();
        Result result = new Result();
        result.setData(workTypeList);
        return result;
    }

}
